package com.len.controller;

import com.len.base.CurrentUser;
import com.len.entity.SpGoods;
import com.len.entity.SpOrder;
import com.len.entity.SysUser;
import com.len.service.SpGoodsService;
import com.len.service.SpOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import java.math.BigDecimal;
import java.util.List;

@Component
public class task {
    @Autowired
    private SpOrderService spOrderService;
    @Autowired
    private SpGoodsService spGoodsService;
    @Scheduled(cron ="0 0 1 * * ?")
    public void zj(){
        List<SpOrder> show5 = spOrderService.show5();
        for (int i=0;i< show5.size();i++){
            String goods = show5.get(i).getTbGoodsid();
            SpGoods spGoods =  spGoodsService.selectId(goods);
            Double price = spGoods.getTbGoodsPrice() ;
            price = price*1.05;
            spGoods.setTbGoodsPrice(price);
            spGoodsService.updatePrice(price,goods);
        }
    }
    @Scheduled(cron ="0 0 1 * * ?")
    public void cs(){
        List<CurrentUser> show5 = spOrderService.show6();
        for (int i=0;i< show5.size();i++){
            CurrentUser goods = show5.get(i);
            double bzj = goods.getTB_BZJ_PRICE();
            String gmcs = null;
            if(bzj>=50&&bzj<100){
                gmcs="3";
            }else if(bzj>=100&&bzj<200){
                gmcs="7";
            }else if(bzj>=200&&bzj<300){
                gmcs="15";
            }else if(bzj>=300){
                gmcs="24";
            }
            spOrderService.subgmcs(gmcs,goods.getId());
//            SpGoods spGoods =  spGoodsService.selectId(goods);
//            Double price = spGoods.getTbGoodsPrice() ;
//            price = price*1.05;
//            spGoods.setTbGoodsPrice(price);
//            spGoodsService.updatePrice(price,goods);
        }
    }
}
